package iteratorPattern;

public class Main {
    public static void main(String[] args) {
        //1. 创建聚合对象--获取迭代器Iterator
        BookCollection collection = new BookCollection();
        collection.addBook("Java");
        collection.addBook("Python");
        collection.addBook("C#");

        //2. 获取迭代器
        Iterator iterator = collection.createIterator();

        //3. 遍历聚合对象
        while (iterator.hasNext()) {
            String book = (String) iterator.next();
            System.out.println(book);
        }


    }
}
